package com.lzdongrui.system.service.impl;

import java.util.List;

import com.lzdongrui.common.annotation.DataScope;
import com.lzdongrui.common.constant.CacheConstants;
import com.lzdongrui.common.utils.DateUtils;
import com.lzdongrui.common.utils.snowid.SnowflakeIdWorker;
import com.lzdongrui.system.domain.Notification;
import com.lzdongrui.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lzdongrui.system.domain.SysNotice;
import com.lzdongrui.system.mapper.SysNoticeMapper;
import com.lzdongrui.system.service.ISysNoticeService;

/**
 * 公告 服务层实现
 * 
 * @author ruoyi
 */
@Service
public class SysNoticeServiceImpl implements ISysNoticeService
{
    @Autowired
    private SysNoticeMapper noticeMapper;

    @Autowired
    private SnowflakeIdWorker snowflakeIdWorker;

    @Autowired
    private ISysConfigService sysConfigService;


    /**
     * 查询公告信息
     * 
     * @param noticeId 公告ID
     * @return 公告信息
     */
    @Override
    public SysNotice selectNoticeById(Long noticeId)
    {
        return noticeMapper.selectNoticeById(noticeId);
    }

    /**
     * 查询公告列表
     * 
     * @param notice 公告信息
     * @return 公告集合
     */
    @Override
    public List<SysNotice> selectNoticeList(SysNotice notice)
    {
        return noticeMapper.selectNoticeList(notice);
    }

    /**
     * 新增公告
     * 
     * @param notice 公告信息
     * @return 结果
     */
    @Override
    public int insertNotice(SysNotice notice)
    {
        return noticeMapper.insertNotice(notice);
    }

    /**
     * 修改公告
     * 
     * @param notice 公告信息
     * @return 结果
     */
    @Override
    public int updateNotice(SysNotice notice)
    {
        return noticeMapper.updateNotice(notice);
    }

    /**
     * 删除公告对象
     * 
     * @param noticeId 公告ID
     * @return 结果
     */
    @Override
    public int deleteNoticeById(Long noticeId)
    {
        return noticeMapper.deleteNoticeById(noticeId);
    }

    /**
     * 批量删除公告信息
     * 
     * @param noticeIds 需要删除的公告ID
     * @return 结果
     */
    @Override
    public int deleteNoticeByIds(Long[] noticeIds)
    {
        return noticeMapper.deleteNoticeByIds(noticeIds);
    }

    /**
     * 新增加一条系统通知目的是提醒教师审核请假申请
     *
     * @param notification
     * @return
     */
    @Override
    public int teacherAuditNoticeAdd(Notification notification) {
        notification.setId(snowflakeIdWorker.nextId());
        notification.setCreateTime(DateUtils.getNowDate());
        notification.setStatus(1);
        notification.setNoticeContent(sysConfigService.selectConfigByKey(CacheConstants.TEACHER_AUDIT_NOTICE));
        return noticeMapper.insertNotification(notification);
    }

    /**
     * 给学生发送假期审核通过通知
     */
    @Override
    public int studentLeavePassAdd(Notification notification) {
        notification.setId(snowflakeIdWorker.nextId());
        notification.setCreateTime(DateUtils.getNowDate());
        notification.setStatus(1);
        notification.setNoticeContent(sysConfigService.selectConfigByKey(CacheConstants.NOTICE_STUDENT_LEAVE_PASS));
        return noticeMapper.insertNotification(notification);
    }

    /**
     * 给学生发送假期审核不通过通知
     */
    @Override
    public int studentLeaveNotpassAdd(Notification notification) {
        notification.setId(snowflakeIdWorker.nextId());
        notification.setCreateTime(DateUtils.getNowDate());
        notification.setStatus(1);
        notification.setNoticeContent(sysConfigService.selectConfigByKey(CacheConstants.NOTICE_STUDENT_LEAVE_NOTPASS));
        return noticeMapper.insertNotification(notification);
    }

    /**
     * 提醒学生假期结束通知
     */
    @Override
    public int studentEndLeave(Notification notification) {
        notification.setId(snowflakeIdWorker.nextId());
        notification.setCreateTime(DateUtils.getNowDate());
        notification.setStatus(1);
        notification.setNoticeContent(sysConfigService.selectConfigByKey(CacheConstants.END_STUDENT_LEAVE));
        return noticeMapper.insertNotification(notification);
    }

    /**
     * 提醒教师学生已返校
     */
    @Override
    public int studentEeturnSchool(Notification notification) {
        notification.setId(snowflakeIdWorker.nextId());
        notification.setCreateTime(DateUtils.getNowDate());
        notification.setStatus(1);
        notification.setNoticeContent(sysConfigService.selectConfigByKey(CacheConstants.STUDENT_RETURN_SCHOOL_NOTICE));
        return noticeMapper.insertNotification(notification);
    }

    @Override
    public List<Notification> notificationAllList(Notification notification) {
        return noticeMapper.notificationAllList(notification);
    }

    @Override
    public int acknowledgeReceipt(Long ids) {
        Notification notification = new Notification();
        notification.setId(ids);
//        notification.setStatus(2);
//        notification.setUpdateTime(DateUtils.getNowDate());
//        return noticeMapper.acknowledgeReceipt(notification);
        noticeMapper.updataNoticeStatis(notification);
        return 1;
    }
}
